feat: verify Headroom proxy health before launching claude#48
Merged
Conversation
Adds a pre-launch health check that pings the Headroom proxy at ANTHROPIC_BASE_URL/health when the URL points at localhost or 127.0.0.1. If curl --fail does not return 200 within 1 second, unset ANTHROPIC_BASE_URL and warn the user that the session will talk to Anthropic directly. This catches the case where shell startup bound the env var because the port was occupied (lsof) but the process behind it is wedged or dead. The check is implemented in lib/proxy-health.sh as a standalone module, sourced from bin/claude-wrapper and called unconditionally before exec (it operates on the wrapper's own env, not project secrets). The function always returns 0 so it cannot abort the wrapper under set -e. Skips silently for unset URLs, non-localhost URLs (user override), and when curl is not installed. Tests in tests/test-proxy-health.sh cover all decision branches plus the set -e safety property. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No blocking issues found. The wrapper restructuring correctly moves VERDICT: PASS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/proxy-health.sh::check_proxy_health()— a pre-launch check that pings${ANTHROPIC_BASE_URL}/health(1s timeout) when the URL points atlocalhostor127.0.0.1. On failure (refused, timeout, HTTP 4xx/5xx), the wrapper unsetsANTHROPIC_BASE_URLand warns the user that the session will fall back to talking to Anthropic directly.bin/claude-wrapperafter secrets/pre-launch logic, beforeexec. Function alwaysreturn 0so it cannot abort the wrapper underset -e.curl.Why
~/.config/bash/services.shexportsANTHROPIC_BASE_URL=http://localhost:8787based on a port-bound check (lsof). That doesn't catch a wedged or dead Headroom process holding the port — every Claude request would then hang or fail. This check verifies the proxy actually responds before we hand control toclaude.Test plan
tests/test-proxy-health.sh— 15 tests covering: unset URL, remote URL (skip), healthy proxy, refused connection (exit 7), HTTP error (exit 22), 127.0.0.1 form, missing curl (graceful),set -esafety, trailing-slash URL handling. All 15 pass.test-wrapper.sh59/59,test-remote-session.sh26/26).shellcheck --severity=warning --exclude=SC2312 --external-sourcesclean on all changed files.CLAUDE_DEBUG=true claude-wrapper --versionwith proxy alive →DEBUG: Headroom proxy healthy at http://localhost:8787.ANTHROPIC_BASE_URL=http://localhost:9999 CLAUDE_DEBUG=true claude-wrapper --version→WARNING: Headroom proxy at http://localhost:9999 is not responding ...then exec proceeds without the env var.🤖 Generated with Claude Code